// Copyright 1995 Matt Brandt.
// Use is governed by the MiscKit license

#import "TinyTermWindow.h"

@implementation TinyTermWindow

- initContent: (const NXRect *)contentRect
	style: (int)aStyle
	backing: (int)backingType
	buttonMask: (int)mask
	defer: (BOOL)flag
{
	self = [super initContent: contentRect style: aStyle
		backing: backingType buttonMask: mask defer: flag];
	port = [[MiscSerialPort alloc] init];
	[port setDeviceName: "/dev/cufa"];
	[port setBaudByName: "9600"];
	[port setDelegate: self];
	if( ![port connect] )
		[self setTitle: "Could not open /dev/cufa"];
	return self;
}

- makeFirstResponder: aResponder
{
	return nil;
}

- keyDown: (NXEvent *)theEvent
{
	char	buf[4];
	
	buf[0] = theEvent->data.key.charCode;
	[port transmitChars: buf length: 1];
	return self;
}

- receiveChars: (char *)buffer length: (int)length
{
	int		i, endpos;
	
	for( i = 0; i < length; ++i )
		if( buffer[i] == '\r' )
			buffer[i] = ' ';
	endpos = [myText textLength];
	[myText setSel: endpos : endpos];
	[myText replaceSel: buffer length: length];
	endpos = [myText textLength];
	[myText setSel: endpos : endpos];
	[myText scrollSelToVisible];
	return self;
}

- hangup
{
	return self;
}


@end
